package com.zjl.itextpdf.controller;

import com.zjl.itextpdf.utils.DataUtil;
import com.zjl.itextpdf.utils.PdfUtll;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * pdf 控制层
 *
 * @author zjl
 */
@Controller
@AllArgsConstructor
public class PdfController {

    // thymeleaf模板引擎
    @Resource
    private PdfUtll pdfUtll;

    /**
     * 导出 pdf
     *
     * @param response 响应体
     */
    @GetMapping("/exportPdf")
    public void exportPdf(HttpServletResponse response) {
        Map<String, Object> schoolDetail = DataUtil.getSchoolDetail();

        pdfUtll.convertToPdf(response, schoolDetail, "purchaseDetail", "测试", null);
    }

    /**
     * 预览 pdf
     *
     * @param response 响应体
     */
    @GetMapping("/previewPdf")
    public void previewPdf(HttpServletResponse response) {
        Map<String, Object> schoolDetail = DataUtil.getSchoolDetail();

        pdfUtll.convertToPdf(response, schoolDetail, "purchaseDetail", null);
    }

}
